﻿Imports System.Linq
Public Class funcoes
    Shared Function MudarEmpresa()
        Dim db As New LinqMainDataContext

        Dim empresa = (From c In db.tblEmpresa1s _
                                          Where c.Empresa = GlobalVariables.Empresa _
                                          Select c.EmpresaDesc).SingleOrDefault

        GlobalVariables.EmpresaDesc = empresa.ToString

        FMain.Text = GlobalVariables.EmpresaDesc & " | SamecaGest"

        For Each frm As Form In FMain.MdiChildren
            frm.Close()
        Next

        Dim dbmain As New LinqMainDataContext

        Dim LinkForm = (From c In dbmain.tblUsers _
                               Where c.UserName = GlobalVariables.UserName _
                               Select c.DashBoard).SingleOrDefault
        If LinkForm <> "" Then
            Dim FullTypeName As String = Application.ProductName & "." & LinkForm.ToString
            Dim FormInstanceType As Type = Type.GetType(FullTypeName, True, True)
            Dim objForm As Form = CType(Activator.CreateInstance(FormInstanceType), Form)

            objForm.MdiParent = FMain
            objForm.Show()

        End If

    End Function

  

End Class
